<template>
  <el-dialog title="审核" :close-on-click-modal="false" :visible.sync="visible" width="30%">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <div v-if="type =='check'">
        <el-form-item label="商品审核">
          <el-radio v-model="dataForm.verify_status" :label="1">审核通过</el-radio>
          <el-radio v-model="dataForm.verify_status" :label="2">审核不通过</el-radio>
        </el-form-item>
        <el-form-item label="理由" v-if="dataForm.verify_status==2">
          <el-select placeholder="请选择理由" v-model="reason_txt">
            <el-option v-for="item in reason" :key="item.name" :label="item.name" :value="item.name"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="其他" v-if="dataForm.verify_status==2&&reason_txt=='其他'">
          <el-input type="textarea" v-model="reason_other_txt" :rows="{min:3}" maxlength="50" placeholder="请输入理由"></el-input>
        </el-form-item>
      </div>
    </el-form>
    <span slot="footer" class="dialog-footer" v-if="type !='view'">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import seviceApi from '@/api/serviceApi.js'
import {
  treeDataTranslate
} from '@/utils'

export default {
  data () {
    return {
      visible: false,
      type: '',
      dataForm: {
        goods_id: null,
        verify_status: 1
      },
      dataRule: {
        type: [{
          required: true,
          message: '菜单名称不能为空',
          trigger: 'blur'
        }],
        name: [{
          required: true,
          message: '菜单名称不能为空',
          trigger: 'blur'
        }]
      },
      reason: [{
        id: 1,
        name: '命名不符合规范'
      }, {
        id: 2,
        name: '与平台商品重复'
      }, {
        id: 3,
        name: '其他'
      }],
      reason_txt: '',
      reason_other_txt: '',
      info: {}
    }
  },

  methods: {
    init (type, row) {
      this.type = type
      console.log(row)
      // this.info = JSON.parse(JSON.stringify(row)) || {};
      this.dataForm.goods_id = row
      this.visible = true
    },
    dataFormSubmit () {
      if (this.dataForm.verify_status == 2) {
        if (!this.reason_txt) {
          this.$message.warning('请选择理由后提交!')
          return
        }
        this.dataForm.remark = this.reason_txt
        if (this.dataForm.remark == '其他') {
          if (this.reason_other_txt) {
            this.dataForm.remark = this.reason_other_txt
          } else {
            this.$message.warning('请填写理由后提交!')
            return
          }
        }
      }
      seviceApi.goodsCheck(this.dataForm).then(res => {
        if (res && res.status == 200 && res.data.code == 200) {
          this.$message.success('审核成功！')
          this.$emit('result')
        }
      })
    }
  }
}
</script>

<style lang="scss">
</style>
